package com.hwh.myapp

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.junit.Test

import org.junit.Assert.*

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    // https://www.cnblogs.com/webor2006/p/11730528.html
    @Test
    fun jobTest() {
        runBlocking {
            val myJob = GlobalScope.launch {
                delay(1000)
                println("kotlin coroutines")
            }
            println("hello")
//    delay(2000)
            myJob.join()
            println("world")

            delay(5000)
        }
    }

    @Test
    fun launchTest() {
        runBlocking {
            launch {
                delay(1000)
                println("kotlin coroutines")
            }
            println("hello")
//    delay(2000)
            println("world")
        }
    }



}